package com.zkthink.zhl.order.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zkthink.base.R;
import com.zkthink.base.service.SuperServiceImpl;
import com.zkthink.clh.order.dto.ChlConfigPageDTO;
import com.zkthink.clh.order.dto.ChlConfigSaveDTO;
import com.zkthink.clh.order.dto.ChlConfigUpdateDTO;
import com.zkthink.clh.order.dto.ParameterTypeDto;
import com.zkthink.clh.order.entity.ChlConfig;
import com.zkthink.clh.order.entity.ChlLbt;
import com.zkthink.zhl.order.dao.ChlConfigMapper;
import com.zkthink.zhl.order.dao.ChlLbtMapper;
import com.zkthink.zhl.order.service.ChlConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 业务实现类
 * 功能价格设置表
 * </p>
 *
 * @author chenke
 * @date 2022-04-24
 */
@Slf4j
@Service
public class ChlConfigServiceImpl extends SuperServiceImpl<ChlConfigMapper, ChlConfig> implements ChlConfigService {
    @Autowired
    private ChlLbtMapper chlLbtMapper;

    @Override
    public R addAdminConfig(ChlConfigSaveDTO dto) {
        QueryWrapper<ChlConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("function_type", dto.getFunctionType());
        ChlConfig chlConfig1 = baseMapper.selectOne(queryWrapper);
        if(chlConfig1 != null){
            return R.fail("不能重复添加");
        }

        ChlConfig chlConfig = new ChlConfig();
        BeanUtils.copyProperties(dto, chlConfig);
        baseMapper.insert(chlConfig);
        return R.success();
    }

    @Override
    public R editAdminConfig(ChlConfig dto) {
        baseMapper.updateById(dto);
        return R.success();
    }

    @Override
    public IPage<ChlConfig> findAdminConfig(IPage page, ChlConfigPageDTO model) {
        return baseMapper.findAdminConfig(page, model);
    }

    @Override
    public ChlConfig findByParameterUnique(String parameterUnique) {
        QueryWrapper<ChlConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parameter_unique", parameterUnique);
        ChlConfig ChlConfig = baseMapper.selectOne(queryWrapper);
        return ChlConfig;
    }

    @Override
    public R parameterType(ParameterTypeDto dto) {
        return R.success(baseMapper.parameterType(dto));
    }

    @Override
    public List<ChlLbt> lbt() {
        return chlLbtMapper.lbt();
    }

    @Override
    public R addlbt(ChlLbt chlLbt) {
        return R.success(chlLbtMapper.insert(chlLbt));
    }

    @Override
    public R deletelbt(Long id) {
        return R.success(chlLbtMapper.deleteById(id));
    }

}
